<template>
	<view class="content">
		<view style="height: 40rpx;"></view>
		<view class="wid80 mar">
			<view class="dis disAl disJuB mar-bott20">
				<view class="foSi30 fowe600" style="color: #D06000;">{{list.type == 2?'代放生':'代许愿'}}</view>
				<view class="foSi20" style="color: #5A5959;">{{list.createtime | formatDate}}</view>
			</view>
			<view v-if="list.fs == 0" class="foSi25 fowe600" style="">放生鱼品种：{{list.goods.name}}</view>
			<view v-if="list.fs != 0" class="foSi25 fowe600" style="">{{list.goods.name}}</view>
			<view class="dis disAl disJuB foSi25 fowe600 mar-top10">
				<view v-if="list.fs == 0" class="webkitLineClamp" style="width: 75%;">放生留言：{{list.note}}</view>
				<view v-if="list.fs != 0" class="webkitLineClamp" style="width: 75%;">许愿内容：{{list.note}}</view>
				<view class="foSi30 " style="color: #C38D5F;">¥{{list.money}}</view>
			</view>
			<view class="wid100 xia mar-top20"></view>
			<view class="foSi30 fowe600" style="margin: 30rpx 0;color: #D06000;">上传视频</view>
			<image v-if="!video" src="../../static/tu13.png" style="width: 237rpx;height: 237rpx;" @click="shangVid()">
			</image>
			<view v-if="video" class="wid100 poRel" style="height: 300rpx;">
				<video class="wh100 borRad10" :src="ossurl+video" object-fit="fill"></video>
				<view @click.stop="shanchu()" class="poAbs" style="right: 10rpx;top: 10rpx;">
					<uni-icons type="closeempty" color="#fff" size="20"></uni-icons>
				</view>
			</view>
			<view class="dis disAl hei80 foSi25 mar-top20">
				<view class="fowe600" style="text-align: end;width: 25%;">负责人：</view>
				<view class="dis disAl hei100" style="border-bottom: 1rpx solid #E5E5E5;width: 75%;">
					<view style="width: 10%;"></view>
					<input class="wid80 hei100 textCen" v-model="name" placeholder="请输入负责人" />
					<view style="width: 10%;"></view>
				</view>
			</view>
			<view class="dis disAl hei80 foSi25">
				<view class="fowe600" style="text-align: end;width: 25%;">放生时间：</view>
				<picker style="width: 75%;" mode="date" :value="date" @change="bindDateChange">
					<view class="dis disAl wid100 hei80" style="border-bottom: 1rpx solid #E5E5E5;">
						<view style="width: 10%;"></view>
						<view class="wid80 textCen" :style="date?'':'color: #8A8A8A;'">{{date?date:'请选择放生时间'}}</view>
						<view class="dis disAl disJuC" style="width: 10%;">
							<image src="../../static/xia.png" style="width: 20rpx;height: 11rpx;"></image>
						</view>
					</view>
				</picker>
			</view>
			<view class="dis disAl hei80 foSi25">
				<view class="fowe600" style="text-align: end;width: 25%;">放生地点：</view>
				<view class="dis disAl hei100" style="border-bottom: 1rpx solid #E5E5E5;width: 75%;">
					<view style="width: 10%;"></view>
					<input class="wid80 hei100 textCen" v-model="address" placeholder="请输入放生地点" />
					<view class="dis disAl disJuC" style="width: 10%;">
						<image src="../../static/dingwei.png" style="width: 20rpx;height: 25rpx;"></image>
					</view>
				</view>
			</view>
		</view>
		<view class="wid100 hei80 poFix" style="bottom: 40rpx;">
			<view class="hei80 dis disAl disJuC borRad10 mar coFFF foSi35"
				style="width: 300rpx;background-color: #C38D5F;" @click="tijaio()">提交</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				ossurl: this.global.ossurl,
				list: [],
				video: '',
				id: '',
				name: '',
				date: '',
				address: ''
			}
		},
		onLoad(option) {
			this.id = option.id
			this.getOrder()
			this.alioss()
		},
		methods: {
			alioss(){
				var that  = this;
				uni.request({
				    // http://jufeng.tengshuokeji.cn//yonghu/order/order_comments
				    url: that.global.url + '/api/index/alioss',
				    method: "POST",
				    data: {},
				    success(res) {
				        let result = res.data
				        console.log(result)
				        if (result.code == 1) {
				            that.global.ossurl = result.data
							console.log(that.global.ossurl);
							that.ossurl = that.global.ossurl;
				        }
				    }
				})
			},
			sendMessage() {
				var that = this
				uni.request({
					url: that.global.url + '/api/user/sendMessage',
					data: {
						id: that.id
					},
					header: {
						'Content-Type': 'application/json', //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					method: 'POST', //请求方式，必须为大写
					success: (res) => {
						let result = res.data
						if (result.code == 1) {
							uni.navigateBack()
						} else {
							uni.showToast({
								title: result.msg,
								icon: 'none',
								duration: 2000
							})
						}
					}
				})
			},
			wechatSendMessage() {
				var that = this
				uni.request({
					url: that.global.url + '/api/user/wechat_sendMessage',
					data: {
						id: that.id
					},
					header: {
						'Content-Type': 'application/json', //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					method: 'POST', //请求方式，必须为大写
					success: (res) => {
						let result = res.data
						if (result.code == 1) {
							uni.navigateBack()
						} else {
							uni.showToast({
								title: result.msg,
								icon: 'none',
								duration: 2000
							})
						}
					}
				})
			},
			tijaio() {
				var that = this
				if (!that.video) {
					return uni.showToast({
						title: '请上传视频',
						icon: 'none',
						duration: 2000
					})
				} else if (!that.name) {
					return uni.showToast({
						title: '请输入负责人',
						icon: 'none',
						duration: 2000
					})
				} else if (!that.date) {
					return uni.showToast({
						title: '请选择放生时间',
						icon: 'none',
						duration: 2000
					})
				} else if (!that.address) {
					return uni.showToast({
						title: '请输入放生地点',
						icon: 'none',
						duration: 2000
					})
				}
				uni.request({
					url: that.global.url + '/api/wish/index',
					data: {
						order_id: parseInt(that.id),
						video: that.video,
						name: that.name,
						releasetime: that.date,
						releaseaddress: that.address,
					},
					header: {
						'Content-Type': 'application/json', //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					method: 'POST', //请求方式，必须为大写
					success: (res) => {
						let result = res.data
						if (result.code == 1) {
							
							if(that.list.method == 'mp'){
								that.wechatSendMessage()
							}else if(that.list.method == 'miniapp'){
								that.sendMessage()
							}
							
						} else {
							uni.showToast({
								title: result.msg,
								icon: 'none',
								duration: 2000
							})
						}
					}
				})
			},
			getOrder() {
				var that = this
				uni.request({
					url: that.global.url + '/api/wish/detail',
					data: {
						id: parseInt(that.id)
					},
					header: {
						'Content-Type': 'application/json', //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					method: 'POST', //请求方式，必须为大写
					success: (res) => {
						let result = res.data
						if (result.code == 1) {
							console.log(result.data);
							that.list = result.data
						} else {
							uni.showToast({
								title: result.msg,
								icon: 'none',
								duration: 2000
							})
						}
					}
				})
			},
			bindDateChange: function(e) {
				this.date = e.detail.value
			},
			shanchu() {
				this.video = ''
			},
			//上传图片
			shangVid() {
				var that = this
				uni.showLoading({
					mask: true,
					title: '上传中...'
				})
				// 1.选择要上传的视频
				uni.chooseVideo({
					maxDuration: 60, // 拍摄视频最长拍摄时间，单位秒。最长支持 60 秒。
					sourceType: ['album', 'camera'], // album 从相册选视频，camera 使用相机拍摄，默认为：['album', 'camera']
					success: (res) => {
						console.log(res.tempFilePath)
						// that.vid = res.tempFilePath;
						that.shangchuan(res.tempFilePath)
					},
					fail() {
						uni.hideLoading()
					}
				});
			},
			shangchuan(tempFilePaths) {
				var that = this
				uni.uploadFile({
					url: that.global.url + '/api/common/upload',
					header: {
						"token": uni.getStorageSync('token'),
					}, //请求token	
					filePath: tempFilePaths,
					name: 'file',
					success: (res) => {
						var apiresult = JSON.parse(res.data)
						if (apiresult.code == 1) {
							console.log(apiresult.data.url);
							that.video = apiresult.data.url;
							uni.hideLoading()
						} else {
							uni.showToast({
								title: apiresult.msg,
								icon: 'error',
								duration: 2000
							})
							uni.hideLoading()
						}
					},
					fail(err) {
						console.log(err)
						uni.showToast({
							title: "网络连接失败",
							icon: 'error',
							duration: 2000
						})
						uni.hideLoading()
					}
				});
			}
		},
		filters: {
			formatDate(value) {
				let date = new Date(value * 1000);
				//时间戳为10位需*1000，时间戳为13位的话不需乘1000
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				MM = MM < 10 ? ('0' + MM) : MM; //月补0
				let d = date.getDate();
				d = d < 10 ? ('0' + d) : d; //天补0
				let h = date.getHours();
				h = h < 10 ? ('0' + h) : h; //小时补0
				let m = date.getMinutes();
				m = m < 10 ? ('0' + m) : m; //分钟补0
				let s = date.getSeconds();
				s = s < 10 ? ('0' + s) : s; //秒补0
				return y + '-' + MM + '-' + d; //年月日
				// return y + '-' + MM + '-' + d + ' ' + h + ':' + m+ ':' + s; //年月日时分秒

			}
		}
	}
</script>

<style>
	.content {
		height: 100vh;
	}

	.xq {
		background-color: #C38D5F;
		width: 130rpx;
		height: 50rpx;
	}

	.xq1 {
		border: 1rpx solid #C38D5F;
		color: #C38D5F;
		width: 130rpx;
		height: 50rpx;
	}

	.xia {
		background-color: #E5E5E5;
		height: 1rpx;
	}
</style>